//第一个c++程序
#include <iostream>
using namespace std;

int main()
{
   cout << "Hello,C++"<<endl;
   return 0;
}


//"cout"是用来执行输出的"对象"
//"cout >> " 是输出
//"endl"是换行符
#include <iostream>
using namespace std;

int main()
{
    cout << "I have " << 3.5 << "dollars." << endl;
	cout << "I want to buy:" << endl << "a book.";
   return 0;
}

//"cin"是用来执行输入的"对象"
//"cin << "是输入
#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	cout << "Please input two number:" << endl;
	cin >> a >> b;
	c = a + b;
	cout << "The sum is" << c <<"!";
	return 0;
}

//数据类型自动转换
#include <iostream>
using namespace std;

int main()
{
	int n1 = 1378;  
	short n2;
	char c = 'a';
	double d1 = 7.809;
	double d2;
	n2 = c;                                  //n2=97,97是'a'的ASCII码值
	cout << "c=" << c << ",n2=" << n2 <<endl;//输出c=a,n2=97
	c = n1;                                  
	cout << "c=" << c << ",n1=" << n1 <<endl;//输出c=b,n1=1378
	n1 = d1;
	cout << "n1 =" << n1 << endl;            //输出n1=7
	d2 = n1;
	cout << d2 << endl;                      //输出d2=7.000000
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int m,n;
	bool b1 = true, b2 = false;
	m = b1;                         //bool类型可以自动被转换成int类型
	n = b2;
	cout << m << "," << n << endl;  //输出1,0
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int a,b = 100;
	unsigned int c;
	a = 0xffffffff;                         //a有符号,因此复制后其值为-1
	c = 0xffffffff;                         //c是无符号整数,因此赋值后其值为 4294967895
	cout << a << "," << c << endl;          //输出 -1，4294967295
	cout << a - b << "," << c - b << endl;  //输出 -101，4294967195
	return 0;
}


//算术运算符
#include <iostream>
using namespace std;

int main()
{
	unsigned int n1 = 0xffffffff;
	cout << n1 << endl;         //输出4294967295
	unsigned int n2 = n1 + 3;   //导致溢出
	cout << n2 << endl;         //输出2
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int a = 10;
	int b = 3;
	double d = a/b;     //a和b都为整形，所以d为整形d=3
	cout << d << endl;  //输出3
    d = 5/2;            //d=2.0  
	cout << d << endl;  //输出2
	d = 5/2.0;
	cout << d << endl;  //输出2.5
	d = (double)a/b;
	cout << d << endl;  //输出3.33333
	return 0;
}

//" a++ "和" ++a "区别
//" a++ "先加后运算
//" ++a "先运算后加
#include <iostream>
using namespace std;

int main()
{
	int n1, n2 = 5;
	n2++;                           //n2=6
	++n2;                           //n2=7
	n1 = n2++;                      //n2=8,n1=7
	cout << n1 << "," << n2 <<endl; //输出7，8
	n1 = ++n2;                      //n1=9 n2=9
	cout << n1 << "," << n1 <<endl; //输出9，9
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int a = 0, b = 1;
	bool n = a++ && b++;            //a=1,n=0,n=flaes 所以后面b++不被执行
	cout << a << "," << b <<endl;   //输出1,1
	n = a++ && b++;                 //a=2,b=2
	cout << a << "," << b <<endl;   //输出2,2
	n = a++ || b++;                 //a=3,b=2 b不被计算是因为a已经使b=true通过
	cout << a << "," << b <<endl;   //输出3,2
	return 0;
}

